{% extends "base.html" %}
{% load common_filters %}
{% load static %}

{% block title %}
    Teacher Dashboard | {{ block.super }}
{% endblock title %}

{% block stylesheets %}
    {{ block.super }}
    <!-- Custom styles for this template -->
    <link href="{% static "laioffer/css/dashboard.css" %}" rel="stylesheet">
    <link href="{% static "hljs/default.min.css" %}" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{% static "css/laioffer/inline_comment.css" %}" rel="stylesheet">
{% endblock stylesheets %}

{% block content %}

    {% if request.user.current_group == "Teacher" %}
        {% include "_teacher_sidebar.html" %}
        {% elif request.user.current_group == "Supervisor" %}
        {% include "_admin_sidebar.html" %}
        {% elif request.user.current_group == "Student" %}
        {% include "_student_sidebar.html" %}
        {% elif request.user.current_group == "Assistant" %}
        {% include "_ta_sidebar.html" %}
    {% endif %}

    <section id="main-content">
        <section class="wrapper">
            <div class="table-agile-info">
                <div class="panel panel-default">
                    {% include "_message.html" %}
                    <section class="panel-heading">{{ view.section_title }}</section>

                    {% with course=exam.course %}
                    <div class="module">
                        <div id="module-contents">
                            {% for problem in exam.problems.all %}

                            {% autoescape off %}
                                {{ problem.formatted_markdown }}
                            {% endautoescape %}

                            {% with answer=problem|get_answer:student_id %}
                            <h3>student's answer</h3>
                            <pre id="answer-{{ answer.id }}" js-answer="{{ answer.id }}"
                                 js-commenter="{{ request.user.id }}" js-is_amendment="false"
                                 class="answer prettyprint linenums">{{ answer.content }}</pre>

                            <h3>student's amendment</h3>
                            <pre id="amendment-{{ answer.id }}" js-answer="{{ answer.id }}"
                                 js-commenter="{{ request.user.id }}" js-is_amendment="true"
                                 class="prettyprint linenums">{{ answer.amendment }}</pre>

                            <form action="{% url "exam:score" exam_paper_id %}" method="POST">
                                {% csrf_token %}
                                <div class="input-group">
                                    <label>Score: </label>
                                    <input type="number" class="form-control inlineblockset" placeholder="score" name="score"
                                           value="{{ answer.score }}" required="required">

                                <input class="inlineblockset" type="hidden" name="answer_pk" value="{{ answer.pk }}">
                                <button class="update2 btn btn-default inlineblockset" type="submit">Update</button>
                                </div>
                            </form>

                            {% endwith %}

                            {% empty %}
                            <p>This exam has no problems yet.</p>
                            {% endfor %}<!-- all problems -->

                            {% with exam_paper=exam|get_exam_paper:student_id %}
                            <h3>Total review</h3>
                            <form action="{% url "exam:score" exam_paper_id %}" method="POST">
                                {% csrf_token %}
                                <div class="form-group">
                                    <textarea name="total_comment"
                                              class="form-control">{{ exam_paper.comment }}</textarea>
                                </div>
                                <div class="input-group">
                                    <h3>Total Score</h3>
                                    <input type="number" class="form-control inlineblockset" placeholder="score" name="total_score"
                                           value="{{ exam_paper.total_score }}" required="required">

                                <input class="inlineblockset" type="hidden" name="exam_paper_pk" value="{{ exam_paper.pk }}">
                                <button class="update2 btn btn-default inlineblockset" type="submit">Update</button>
                                </div>
                            </form>
                            {% endwith %}

                        </div>
                    </div>
                    {% endwith %}

                    {% if view.task %}
                        <span id='task_status' data-task_status="{{ view.task.status }}"></span>
                    {% endif %}

                </div>
            </div>
        </section> <!-- /wrapper -->
    </section> <!-- /main-content -->



{% endblock content %}

{% block javascripts %}
    {{ block.super }}
    <script type="text/javascript">
        $.py = {};
        $.py.exam_id = {{ exam.id }};
        $.py.student_id = {{ student_id }};
        $.py.current_user = {{ request.user.id }};
        {% if view.task.id %}
        $.py.task_id = {{ view.task.id }};
        {% endif %}
    </script>
    <script type="text/javascript" src="{% static "js/moment.js" %}"></script>
    <script type="text/javascript" src="{% static "laioffer/js/csrf.js" %}"></script>
    <script type="text/javascript" src="{% static "laioffer/js/rest/task.js" %}"></script>
    <script type="text/javascript" src="{% static "js/laioffer/task_btn.js" %}"></script>
    <script type="text/javascript" src="{% static "laioffer/js/inlinecomment.js" %}"></script>
    <link href="{% static "code-prettify/prettify.css" %}" rel="stylesheet" type="text/css">
    <script src="{% static "code-prettify/prettify.js" %}" type="text/javascript"></script>
    <script type="text/javascript">
        load_all_comments();
        $(document).ready(function () {
            prettyPrint(printprint_finished);
        });
    </script>
{% endblock javascripts %}
